package hiepst.solution;

/**
 * Problem Statement
 * <p>
 * This task is about the scoring in the first phase of the die-game Yahtzee,
 * where five dice are used. The score is determined by the values on the upward
 * die faces after a roll. The player gets to choose a value, and all dice that
 * show the chosen value are considered active. The score is simply the sum of
 * values on active dice. Say, for instance, that a player ends up with the die
 * faces showing 2, 2, 3, 5 and 4. Choosing the value two makes the dice showing
 * 2 active and yields a score of 2 + 2 = 4, while choosing 5 makes the one die
 * showing 5 active, yielding a score of 5. Your method will take as input a
 * int[] toss, where each element represents the upward face of a die, and
 * return the maximum possible score with these values.<br>
 * </p>
 * 
 * Definition<br>
 * 
 * Class: YahtzeeScore<br>
 * Method: maxPoints<br>
 * Parameters: int[]<br>
 * Returns: int <br>
 * Method signature: int maxPoints(int[] toss)<br>
 * (be sure your method is public)<br>
 * 
 * Limits<br>
 * 
 * Time limit (s): 2.000<br>
 * Memory limit (MB): 64<br>
 * 
 * Constraints<br>
 * - toss will contain exactly 5 elements.<br>
 * - Each element of toss will be between 1 and 6, inclusive.<br>
 * 
 * Examples<br>
 * 
 * 0) { 2, 2, 3, 5, 4 }<br>
 * Returns: 5<br>
 * The example from the text.<br>
 * 
 * 1) { 6, 4, 1, 1, 3 }<br>
 * Returns: 6<br>
 * Selecting 1 as active yields 1 + 1 = 2, selecting 3 yields 3,<br>
 * selecting 4 yields 4 and selecting 6 yields 6, which is the maximum number of
 * points.<br>
 * 
 * 2) { 5, 3, 5, 3, 3 }<br>
 * Returns: 10<br>
 * 
 * <p>
 * This problem statement is the exclusive and proprietary property of TopCoder,
 * Inc. Any unauthorized use or reproduction of this information without the
 * prior written consent of TopCoder, Inc. is strictly prohibited. (c)2003,
 * TopCoder, Inc. All rights reserved.
 * </p>
 * 
 * 
 * @author Hiep.Hong
 * 
 */
public class SRM146DIV2_YahtzeeScore {

	public int maxPoints(int[] toss) {
		int max = 0;
		for (int i = 0; i < toss.length; i++) {
			int current = toss[i];
			for (int j = 0; j < toss.length; j++) {
				if (i != j && toss[i] == toss[j]) {
					current += toss[j];
				}
			}
			max = Math.max(max, current);
		}

		return max;
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		SRM146DIV2_YahtzeeScore yahtzeeScore = new SRM146DIV2_YahtzeeScore();
		int maxPoints = yahtzeeScore.maxPoints(new int[] { 2, 2, 3, 5, 4 });
		System.out.println("maxPoints = " + maxPoints);

		maxPoints = yahtzeeScore.maxPoints(new int[] { 6, 4, 1, 1, 3 });
		System.out.println("maxPoints = " + maxPoints);

		maxPoints = yahtzeeScore.maxPoints(new int[] { 5, 3, 5, 3, 3 });
		System.out.println("maxPoints = " + maxPoints);
	}

}
